import 'dart:convert';
import 'package:qr_code_app/module/user/entity/user_entity.dart';
import 'package:todo_flutter/todo_flutter.dart';

class AppData {
  ///引导
  static void setGuide(bool guide) {
    PreferencesUtil.putBool('guide', guide);
  }

  static bool showGuide() {
    return PreferencesUtil.getBool('guide', defaultValue: true);
  }

  ///是否开启代理
  static void setProxy(bool proxy) {
    PreferencesUtil.putBool('proxy', proxy);
  }

  static bool getProxy() {
    return PreferencesUtil.getBool('proxy');
  }

  static void setProxyIp(String proxyIp) {
    PreferencesUtil.putString('proxyIp', proxyIp);
  }

  static String getProxyIp() {
    return PreferencesUtil.getString('proxyIp');
  }

  static void setEnv(String env) {
    PreferencesUtil.putString('env', env);
  }

  static String getEnv() {
    return PreferencesUtil.getString('env');
  }

  ///未登录-匿名id
  static void setAnonymousId(String anonymousId) {
    PreferencesUtil.putString('anonymousId', anonymousId);
  }

  static String getAnonymousId() {
    return PreferencesUtil.getString('anonymousId');
  }

  ///token
  static void setToken(String? entity) {
    PreferencesUtil.putString('token', entity ?? '');
  }

  static String? getToken() {
    final data = PreferencesUtil.getString('token');
    if (ObjectUtil.isNotEmpty(data)) {
      return data;
    }
    return null;
  }

  static void setNotify(bool notify) {
    PreferencesUtil.putBool('notify', notify);
  }

  static bool getNotify() {
    return PreferencesUtil.getBool('notify', defaultValue: true);
  }

  ///user
static void setUser(UserEntity? entity) {
  PreferencesUtil.putString('user', entity?.toString() ?? '');
}

static UserEntity? getUser() {
  final data = PreferencesUtil.getString('user');
  if (ObjectUtil.isNotEmpty(data)) {
    return UserEntity.fromJson(jsonDecode(data));
  }
  return null;
}
}
